<script setup>import { ref, nextTick } from 'vue';
import { goCommunity, goHome } from "../../tools/go";
import UniSection from "../../uni_modules/uni-section/components/uni-section/uni-section.vue";
import UniNumberBox from "../../uni_modules/uni-number-box/components/uni-number-box/uni-number-box.vue";
import UniDatetimePicker
  from "../../uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue";
import {getHousePer} from "../../api/house/house";
import UniPopup from "../../uni_modules/uni-popup/components/uni-popup/uni-popup.vue";
import UniPopupDialog from "../../uni_modules/uni-popup/components/uni-popup-dialog/uni-popup-dialog.vue";
import {baseUrl} from "../../api/http";

// 访客目的列表
const list = [
  { id: 1, name: '亲戚来访' },
  { id: 2, name: '朋友来访' },
  { id: 3, name: '快递配送' },
  { id: 4, name: '家政服务' },
  { id: 5, name: '维修服务' },
  { id: 6, name: '送餐外卖' },
  { id: 7, name: '其他' },
];

const num = ref(0);
const showModal = ref(false);
const modalType = ref('');
const customInput = ref('');
const inputRef = ref(null);
const selectedPurpose = ref('亲戚来访');
const appointmentTime = ref(''); // 定义时间变量

// 处理时间选择器变化
const onAppointmentTimeChange = (event) => {
  appointmentTime.value = event.detail.value; // 更新选择的时间
};

// 处理按钮点击
const handleButtonClick = (type) => {
  getHousePer({}).then(res => {
      fileUrl.value = res.data
      dia.value.open()
  })
};


const dia = ref()
const fileUrl = ref("")


</script>

<template>

  <uni-popup ref="dia">
      <view>
        <img :src="fileUrl" />
      </view>
  </uni-popup>

  <!-- 标题 -->
  <view class="titli">
    <v-icon @click="flag == 1 ? goCommunity() : goHome()" class="icon" icon="mdi-chevron-left"></v-icon>
    <h3>访客邀请</h3>
  </view>
  <view class="container">
  <uni-section title="选择来访目的" type="line" titleFontSize="20px" >
        <view class="one">
          <select class="sel" v-model="selectedPurpose">
            <option v-for="item in list" :key="item.id" :value="item.name">{{ item.name }}</option>
          </select>
        </view>
  </uni-section>

  <uni-section title="来访人数" type="line" titleFontSize="20px" >
    <uni-number-box></uni-number-box>
  </uni-section>

  <uni-section title="来访时间" type="line" titleFontSize="20px" >
    <uni-datetime-picker></uni-datetime-picker>
  </uni-section>

  </view>

  <button class="bnt w" @click="handleButtonClick('生成密钥')">生成二维码</button>
</template>


<style scoped lang="scss">
@import "../../static/css/title/index.css";
.container{
  .one{
    .i{
      .time-selector{
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
      }
      margin-top: 10px;
      display: flex;
      width: 100%;
      height: 50px;
      justify-content: space-between;
      background: #cacaca;
      align-items: center;
      padding: 11px;
      border-radius: 6px;
    }
    .sel{
      margin-bottom: 10px;
      width: 95%;
      height: 50px;
      border-radius: 7px;
      padding: 12px;
      border: 1px solid #CACACA;
    }
    .box{
      text{

        display: block;
        background: #CACACA;
        width: 70px;
        margin: 10px 10px;
        text-align: center;
        line-height: 50px;
        height: 50px;
        font-size: 17px;
      }
      button{
        width: 50px;
        height: 50px;
        border: none;
        font-size: 17px;
        line-height: 50px;
      }
      display: flex;
      align-items: center;
    }
    input{
      width: 95%;
      height: 50px;
      border-radius: 7px;
      padding: 12px;
      border: 1px solid #CACACA;
      margin-bottom: 10px;
    }
    h4:after{
      content: "";
      position: absolute;
      top: 0;
      left: -10px;
      display: block;
      width: 8px;
      height: 25px;
      background: #0e75e8;
      border-radius: 12px;
    }
    h4{
      position: relative;
      margin-bottom: 10px;
      margin-left: 10px;
      font-size: 17px;
      font-weight: 400;
      color: #000000;
    }
  }
  padding: 12px;
  display: flex;
  flex-direction: column;
}
.nav:hover{
  padding: 2px;
}
.nav:active{
  padding: 2px;
  //box-shadow: 10px 5px 5px #CACACA;
}

/* 灰色蒙层 */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 100;
}

/* 弹窗 */
.custom-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80%;
  max-width: 300px;
  background: white;
  padding: 20px;
  border-radius: 10px;
  z-index: 101;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  text-align: center;

  h4 {
    margin-bottom: 15px;
    font-size: 18px;
    color: #333;
  }

  input {
    width: 100%;
    height: 40px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    margin-bottom: 15px;
    font-size: 16px;
  }

  .modal-buttons {
    display: flex;
    justify-content: space-between;

    button {
      flex: 1;
      padding: 10px;
      border: none;
      border-radius: 5px;
      font-size: 16px;
      cursor: pointer;

      &.cancel-btn {
        background: #f5f5f5;
        color: #666;
        margin-right: 10px;
      }

      &.confirm-btn {
        background: #FF702E;
        color: white;
      }
    }
  }
}

/* 其他样式保持不变 */
.bnt {
  position: relative;
  top: 100px;
  background: #0e75e8;
  color: #FFFFFF;
  font-size: 18px;
}

.tiem {
  .one:nth-child(2) {
    margin: 20px 0;
  }
  .one {
    view {
      .t {
        font-size: 17px;
        display: block;
        width: 100%;
        border-bottom: 2px solid #CACACA;
      }
      text {
        font-size: 14px;
      }
      width: 77%;
      margin-left: 10px;
      display: flex;
      flex-direction: column;
    }
    h4 {
      margin-left: 10px;
      font-weight: 500;
      font-size: 18px;
    }
    display: flex;
    align-items: center;
  }
  display: flex;
  flex-direction: column;
  margin-top: 20px;
}

.list {
  ul {
    li {
      button {
        height: 45px;
        line-height: 45px;
        text-align: center;
        font-size: 17px;
        border-radius: 5px;
        background: #FF702E;
        border: none;
        color: white;
        width: 100%;
        cursor: pointer;
      }
      transition: 0.3s all;
    }
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-gap: 10px;
    margin-top: 10px;
  }
  h4 {
    font-weight: 500;
    font-size: 18px;
  }
}
</style>